﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.IO;
using System.ComponentModel;
using Equin.ApplicationFramework;

namespace TimeReporter
{
    public class TaskObject : INotifyPropertyChanged
    {

        private int _projectID;
        private int _taskID;
        private float _timeSpent;
        private string _userID;
        private DateTime _endDateTime;
        private DateTime _startDateTime;

        public event PropertyChangedEventHandler PropertyChanged;

        private void NotifyPropertyChanged(string info)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(info));
            }
        }

        public TaskObject()
        {
        }
        public TaskObject(string importString)
        {
            char[] charArray = new char[] { ',' };

            //Extract the task data
            string[] theTask = importString.Split(charArray);

            
            _taskID = (int)Convert.ToDecimal(theTask[0]);
            //theTask[0].Trim();
            _timeSpent = (float)Convert.ToDouble(theTask[1]);
            _userID = theTask[2].Trim();
            _endDateTime = Convert.ToDateTime(theTask[3]);
            _startDateTime = Convert.ToDateTime(theTask[4]);

            NotifyPropertyChanged("New object");
        }

        public TaskObject(string importString, int ProjectID)
        {
            char[] charArray = new char[] { ',' };

            //Extract the task data
            string[] theTask = importString.Split(charArray);

            _projectID = ProjectID;
            _taskID = (int)Convert.ToDecimal(theTask[0]);
                //theTask[0].Trim();
            _timeSpent = (float)Convert.ToDouble(theTask[1]);
            _userID = theTask[2].Trim();
            _endDateTime = Convert.ToDateTime(theTask[3]);
            _startDateTime = Convert.ToDateTime(theTask[4]);

            NotifyPropertyChanged("New object");
        }

        public static string FileInfoToProjectName(FileInfo fi)
        {
            char[] charArray2 = new char[] { '_' };
            string[] tmp = fi.Name.Split(charArray2);

            return tmp[0].Trim();
        }

        public int ProjectID
        {
            get { return _projectID; }
            set {
                if (value != _projectID)
                {
                    _projectID = value;
                    NotifyPropertyChanged("ProjectID");
                }
            }
        }

        public int TaskId
        {
            get { return _taskID; }
           // set { _taskID = value; }
        }

        public float TimeSpent
        {
            get { return _timeSpent; }
           // set { _timeSpent = value; }
        }

        public string UserId
        {
            get { return _userID; }
           // set { _userID = value; }
        }

        public DateTime EndDateTime
        {
            get { return _endDateTime.Date; }
           // set { _endDateTime = value; }
        }

        public DateTime StartDateTime
        {
            get { return _startDateTime.Date; }
           // set { _startDateTime = value; }
        }

        
    }
}
